mod architecture;
mod meta_connector;
mod operator;
mod paging;
mod persistence;
mod value;
use std::sync::RwLock;
pub mod meta;
mod relation;

pub use relation::*;
pub use architecture::*;
pub use meta_connector::*;
pub use operator::*;
pub use paging::*;
pub use persistence::*;
pub use value::*;

use crate::database::DataSource;

use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub enum ModelingVersion {
    #[default]
    #[serde(rename = "V1.0.0")]
    Version1_0_0,
}

// 系统库

lazy_static::lazy_static! {

    pub(crate) static ref SYSTEM_META_DATABASE: RwLock<DataSource> = RwLock::new(DataSource{
        database_type:crate::database::DatabaseType::SQLite,
        protocol:crate::database::ConnectorProtocol::SQLite,
        url:String::from("sqlite:./g01.sqlite"),
        ..Default::default()
    });
}

pub fn set_system_meta_database(database: DataSource) -> anyhow::Result<()> {
    let mut ds = SYSTEM_META_DATABASE
        .write()
        .map_err(|err| anyhow::anyhow!("获取SYSTEM_META_DATABASE失败!{}", err))?;

    *ds = database;
    Ok(())
}

pub fn system_meta_database() -> anyhow::Result<DataSource> {
    Ok(SYSTEM_META_DATABASE
        .read()
        .map_err(|err| anyhow::anyhow!("获取SYSTEM_META_DATABASE失败!{}", err))?
        .clone())
}
